Calculate the geometric sum of N - 1¶
Calculate the geometric sum of N - 1.
Note:
In mathematics, a geometric series is a series
with a constant ratio between successive terms.
Example:
harmonic series
def geometric_sum(n):
if n < 0:
return 0
else:
return 1 / (pow(2, n)) + geometric_sum(n - 1)
# test
print(geometric_sum(7)) # 1.9921875
print(geometric_sum(4)) # 1.9375